/*
 * A versatile set of functions for dealing with linked lists
 * Can function as a FIFO/LIFO stack
 * Can efficiently iterate of lists forwards and backwards
 */

#ifndef mW_list_include
#define mW_list_include



#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "error.h"


#define DEBUG 1


typedef struct _mW_list_item
{
	int id;
	void * data;
	struct _mW_list_item * next_item;
	struct _mW_list_item * previous_item;
} mW_list_item;

typedef struct
{
	int size;
	int next_id;
	mW_list_item * first;
	mW_list_item * last;
	mW_list_item * iterator;
} mW_list;



mW_list * mW_list_create();

int mW_list_delete (mW_list * list, int id);
int mW_list_delete_all (mW_list * list);
int mW_list_delete_first (mW_list * list);
int mW_list_delete_last (mW_list * list);

int mW_list_destroy (mW_list * list);
int mW_list_destroy_items (mW_list_item * list_item);

void * mW_list_get_by_id (mW_list * list, int id);
void * mW_list_get_first (mW_list * list);
int    mW_list_get_id (mW_list * list, void * data);
void * mW_list_get_last (mW_list * list);
int    mW_list_get_size (mW_list * list);

int mW_list_insert (mW_list * list, void * data);
int mW_list_insert_first (mW_list * list, void * data);

void * mW_list_dont_iterate (mW_list * list); 
void * mW_list_iterate (mW_list * list, int direction);
int    mW_list_reset_iterator (mW_list * list, int direction);



#endif // mW_list_include
